package com.itheima;

/**
 * 2025/5/16 20:06
 */
public class LambdaDemo {

    public static void sound1(){
        System.out.println("动物1叫");
    }
    public void sound2(){
        System.out.println("动物2叫");
    }
    public static void main(String[] args) {
        //创建Animal的你们内部类对象
        Animal a1 = new Animal() {
            @Override
            public void sound() {
                System.out.println("动物叫");
            }
        };
        //改写为Lambda表达式的形式
        Animal a2 = () -> System.out.println("动物叫");
        //改写成方法引用的形式（静态方法）
        Animal a3 = LambdaDemo::sound1;
        //改成方法引用的形式（实例方法）
        Animal a4 = new LambdaDemo()::sound2;

        a2.sound();

    }

    public static void testA() {
        A a1 = new A() {
            @Override
            public void show(String name, int age) {
                System.out.println("name = " + name + ",age = " + age);
            }
        };

        A a2 = (name, age) -> System.out.println("name = " + name + ",age = " + age);
    }

    public static void testB() {
        B b1 = new B() {
            @Override
            public void show(String name) {
                System.out.println("name = " + name);
            }
        };

        B b2 = name -> System.out.println("name = " + name);

    }

    public static void testC() {
        C c1 = new C() {
            @Override
            public String show(String name) {
                return "name=" + name;
            }
        };

        C c2 = name -> name;

    }

    public static void testD() {
        D d1 = new D() {
            @Override
            public int max(int a, int b) {
                return a > b ? a : b;
            }
        };

        D d2 = (a, b) -> a > b ? a : b;
    }


}
